<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--Converted with LaTeX2HTML 96.1 (Feb 5, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->


<title>Big Mod</title>
<meta name="description" content="Big Mod">
<meta name="keywords" content="htmlatex">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<link rel="STYLESHEET" href="acm-00374_files/htmlatex.css">
</head><body bgcolor="#ffffff" lang="EN">
 <h1><br clear="ALL"><center><table bgcolor="#0060f0"><tbody><tr><td><b><font color="#c0ffff" size="5">&nbsp;<a name="SECTION0001000000000000000000">Big Mod</a></font>&nbsp;</b></td></tr></tbody></table></center></h1>
<p>
Calculate
</p><p>
</p><p> <img alt="displaymath25" src="acm-00374_files/374img1.gif" height="17" width="313" align="BOTTOM"> </p><p>
</p><p>
for large values of <i>B</i>, <i>P</i>, and <i>M</i> using an efficient algorithm. 
(That's right, this problem has a time dependency !!!.)
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001001000000000000000">Input</a></font></h2>
<p>
     Three integer values (in the order <i>B</i>, <i>P</i>, <i>M</i>) will be read one number per line.  <i>B</i> and <i>P</i> are integers in the range 0 to 2147483647 inclusive.  <i>M</i> is an integer in the range 1 to 46340 inclusive.
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001002000000000000000">Output</a></font></h2>
<p>
     The result of the computation.  A single integer.
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001003000000000000000">Sample Input</a></font></h2>
<p>
</p><pre>3
18132
17

17
1765
3

2374859
3029382
36123</pre>
<p>
</p><h2><font color="#0070e8"><a name="SECTION0001004000000000000000">Sample Output</a></font></h2>
<p>
</p><pre>13
2
13195</pre>
<p>
</p></body></html>